package Frame;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class MainFrame implements ActionListener{
	JPanel firstPanel;
	JPanel howtoPanel;
	public GamePanel gamePanel;
	public OverPanel overPanel;
	JButton btn_start, btn_howto, btn_exit, btn_start2;
	JFrame frame; 
	public MainFrame(){
		frame = new JFrame();
		frame.setResizable(false);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		firstPanel = new JPanel(null);
		howtoPanel = new JPanel(null);
		gamePanel = new GamePanel();
		overPanel = new OverPanel();
		
		/**Panel background setting*/
		ImageIcon img_background = new ImageIcon("images/firstground.png");
		ImageIcon img_howto = new ImageIcon("images/howto.png");
		JLabel lab_bg = new JLabel("", img_background,SwingConstants.CENTER);
		JLabel lab_howto = new JLabel("", img_howto,SwingConstants.CENTER);
		lab_bg.setSize(1300,650);
		lab_bg.setLocation(0,0);
		lab_howto.setSize(1300,650);
		lab_howto.setLocation(0,0);
		
		/**img and label setting*/
		//start button
		btn_start = new JButton(new ImageIcon("images/btn_start.png"));
		btn_start2 = new JButton(new ImageIcon("images/btn_start.png"));
		btn_howto= new JButton(new ImageIcon("images/btn_howto.png"));
		btn_exit= new JButton(new ImageIcon("images/btn_exit.png"));

		btn_start.setBounds(80, 450, 334, 117);
		btn_start2.setBounds(800, 100, 334, 117);
		btn_howto.setBounds(440, 450, 385, 117);
		btn_exit.setBounds(850, 450, 328, 117);
		
		/**add objects in the firstPanel*/
        firstPanel.add(btn_start);
        firstPanel.add(btn_howto);
        firstPanel.add(btn_exit);
        firstPanel.add(lab_bg);
        firstPanel.setPreferredSize(new Dimension(1300,650));
        firstPanel.setVisible(true);
        
        btn_start2.addActionListener(this);
        howtoPanel.add(btn_start2);
        howtoPanel.add(lab_howto);
        howtoPanel.setPreferredSize(new Dimension(1300,650));
        
        /**add Panel in the frame*/
        frame.add(firstPanel);
        frame.add(gamePanel,BorderLayout.EAST);
        frame.add(overPanel,BorderLayout.NORTH);
        frame.add(howtoPanel,BorderLayout.WEST);
        howtoPanel.setVisible(false);
        frame.pack();
        frame.setVisible(true);
        
        /**button Action listener*/
        btn_start.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                firstPanel.removeAll();
                gamePanel.setVisible();
            }
        });
        btn_howto.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            	firstPanel.setVisible(false);
    			howtoPanel.setVisible(true);
            }
        });
        btn_exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            	System.exit(0);
            }
        });
	}
	public void death() {
        gamePanel.removeAll();
        overPanel.setVisible(true);
    }
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getSource()==btn_start2){
			howtoPanel.removeAll();
			gamePanel.setVisible();
		}
	}
}
